import pandas as pd
import akshare as ak
import time


# ETF基金历史行情 - 东财
# code = "513180" # 恒生科技指数
# start_date = "2019-01-01"
# end_date = time.strftime("%Y%m%d", time.localtime())
#
# df = ak.fund_etf_hist_em(symbol=code, start_date=start_date, end_date=end_date, adjust="qfq")
# rs = df.describe()

# max, min = rs['最高']['max'], rs['最低']['min']
max, min = 1.043, 0.39
cur = max
prices = [max]
percents = ["0%"]
batches = [0]
moneys = [0]
while cur > min:
    cur = round(cur * 0.95, 3)
    if cur < min:
        break
    prices.append(cur)
    percent = round(100 - cur * 100 / max, 1)
    # 回撤比例超过40%再入手
    if percent <= 40:
        batches.append(0)
        moneys.append(0)
    else:
        batches.append(batches[-1]+1)
        moneys.append(1000)
    percents.append(f"{percent}%")
if prices[-1] > min:
    prices.append(min)
    per = round(100 - min * 100 / max, 2)
    percents.append(f"{per}%")
    batches.append(batches[-1] + 1)
    moneys.append(1000)

data = {
    "基金价格": prices,
    "回撤比例": percents,
    "加仓批次": batches,
    "金额": moneys,
}

df = pd.DataFrame(data)
print(df)